/*
 * When the ControlButton is clicked, it bounces and shrinks to the lower-right.
 * Meanwhile, the MainMenu grows from point clicked, (0 X 0)px, transparent to a
 * full size rectangle (dictated by the size of the text). The sequence ends with
 * a subtle jog to the left. Finer tuning will result in increased user happiness.
 *
 * TODO: Set min/max size constraint.
 */

#include "MainMenu.hpp"

#include <Wt/WPopupMenuItem>
#include <Wt/WApplication>
#include <Wt/WPopupMenu>
#include <Wt/WMenuItem>
#include "utilities.hpp" // for loadStylesheet()
#include "ControlButton.hpp" // no longer needed here?

// using namespace Wt;
// using namespace webpages;
// using namespace components;

#include <Wt/WText>

MainMenu::MainMenu(): WPopupMenu()
{
  Wt::WText *status = new Wt::WText();
  status->setMargin(10, Wt::Left | Wt::Right);

  Wt::WText *out = new Wt::WText();
  
  // Create some menu items for the popup menu
  addItem("Connect")->triggered().connect(std::bind([=] () 
  {
    out->setText("<p>Connecting...</p>");
  }));
}



// commented for testing
// MainMenu::MainMenu()
// {
//     utilities::loadStylesheet("/css/mainmenu.css"); 
//     setStyleClass("mainmenu");
//         
//     //aboutToHide().connect(this, &MainMenu::hideSubMenu);
//         
//     addMenuItem("Datalogger", false);
//     addMenuItem("Instruments", false);
//     addMenuItem("Site", false);
//     addMenuItem("Channels", false);
//     addMenuItem("---", false);
//     addMenuItem("Reports", false);
// }

void MainMenu::addMenuItem(std::string item_name, bool enable_checkBox)
{
    if (item_name == "---")
    {
        addSeparator();
        return;
    }
    
//     Wt::WPopupMenuItem* item = new Wt::WPopupMenuItem(Wt::WString::fromUTF8(item_name));
//     item->setStyleClass("menuitem");
//     item->setCheckable(enable_checkBox);
    //item->setIcon("resources/button-show_home.png");
    
    addItem("MyFooBar");

    //add(item); //what did I write this for? Old Wt version used this.
}

void MainMenu::showWithAnimation()
{
    //I could not get internal animation to work so went with external CSS addStyleClass()
    //animateShow(WAnimation(WAnimation::Pop | WAnimation::Fade, WAnimation::Linear, 250));
    //setStyleClass("startanimated");

    addStyleClass("animation_settings");
}
